<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/taglibs.jsp"%>
<%@ include file="/commons/commonEdit.jsp"%>
<%@ include file="/commons/validation.jsp"%>
<%@ include file="/commons/dateTime.jsp" %>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>许可证发证</title>
<script type="text/javascript" src="${ctx}/scripts/public3.js"></script>
<script type="text/javascript" src="${ctx}/scripts/public.js"></script>
<script type="text/javascript" src="${ctx}/scripts/common/prototype.js"></script>
<script type="text/javascript" src="${ctx}/scripts/common.js"></script>
<script language="JavaScript"  src="${ctx}/scripts/div/common.js"></script>
<script type="text/javascript" src="${ctx}/scripts/ajaxException.js"></script>

<script>
	function setDays(){	//计算装修天数
		beginDate =  $('beginDate').value;
		endDate=$('endDate').value;

		endList = endDate.split("-")
		endDate = new Date(endList[1] + '-' + endList[2] + '-' + endList[0]) //转换为12-18-2002格式

		beginList = beginDate.split("-")
		beginDate = new Date(beginList[1] + '-' + beginList[2] + '-' + beginList[0])

		if (beginDate > endDate){
			$('renovateDays').value="";
			return ;
		}

		var iDays = parseInt(Math.abs(endDate - beginDate) / 1000 / 60 / 60 /24) //把相差的毫秒数转换为天数

		if (isNaN(iDays)){
			$('renovateDays').value="";
		}else{
			$('renovateDays').value=iDays+1;
		}
	}

	function submitWin(){	//保存
		var isTrue=$("licenceForm").fireEvent("onSubmit");
  		if(isTrue){
  			setButtonStatus(false);
			var params = $("licenceForm").serialize();
			var url = "${ctx}/renovation_renovateRequisitionAction.do?method=editTransactLicence";
			sendAjaxRequest(url,params,function(response){
				setButtonStatus(true);
				ajaxSubmitException(response.responseText);
				findFrame('main').refleshRenReqFrame(); //刷新主页面列表

				windowClose();
			});
		}
	}

	function submitAndPreview(){	//先保存（保存并预览）
		var isTrue=$("licenceForm").fireEvent("onSubmit");
  		if(isTrue){
  			setButtonStatus(false);
			var params = $("licenceForm").serialize();
			var url = "${ctx}/renovation_renovateRequisitionAction.do?method=editTransactLicence";
			sendAjaxRequest(url,params,backPreview);
		}
	}
	function backPreview(response){
		setButtonStatus(true);
		ajaxSubmitException(response.responseText);
		var licenceId = response.responseText;

		$('printFrom').action ="${ctx}/applets/appletShow.jsp?reportName=licenceReport&licenceId="+licenceId;
	 	$('printFrom').submit();

	 	windowClose();
	}

	function setButtonStatus(status){ //设置按钮状态 true 代表可用 false代表不可用
		$("btn1_42").disabled = !status;
		$("btn1_22").disabled = !status;
		$("btn1_32").disabled = !status;
	}

	function init(){
		setDays();
	}

</script>
</head>

<body onload="init();">

<form id="printFrom" name="printFrom" method="post"
	   action="${ctx}/applets/appletShow.jsp?reportName=ChargeVoucherReport" target="_blank">
</form>
<div style="height: 320px;overflow: auto;">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td class="window_head_outBg">
	    <table border="0" cellpadding="0" cellspacing="0">
	      <tr><td><img src="${ctx}/images/ico_Advance.gif" width="16" height="16" align="absmiddle" /> <span class="window_head_intext">许可证发证</span></td></tr>
	    </table>
    </td>
  </tr>
  <tr><td class="aux_header_line_1"></td></tr>
  <tr><td class="aux_header_line_2"></td></tr>
  <tr>
    <td class="content">

<form  name="licenceForm" id="licenceForm" method="post" action=""  class="required-validate">
	<input type="hidden" id="keyword" name="keyword" value="${licenceVO.keyword}">
	<input type="hidden" id="requisitionId" name="requisitionId" value="${requisitionVO.keyword }">
	<input type="hidden" id="licenceNumber" name="licenceNumber" value="${requisitionVO.requisitionNumber }">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
          <td class="aux_outtable_color"><table width="100%" border="0" cellpadding="0" cellspacing="1" class="aux_intable_color">
			  <tr>
			    <td class="aux_intable_td1">楼 栋： </td>
			    <td class="aux_intable_td2">${requisitionVO.buildingName }</td>
			    <td class="aux_intable_td1">现场负责人：</td>
			    <td class="aux_intable_td2">${requisitionVO.burdenMan }</td>
			  </tr>
			  <tr>
			    <td class="aux_intable_td1">房 号：</td>
			    <td class="aux_intable_td2">${requisitionVO.houseNumber }</td>
			    <td class="aux_intable_td1">现场负责人联系电话：</td>
			    <td class="aux_intable_td2">${requisitionVO.burdenManPhone }</td>
			  </tr>
			  <tr>
			  <td class="aux_intable_td1">业主姓名：</td>
              <td class="aux_intable_td2">${requisitionVO.clientNames }</td>
              <td class="aux_intable_td1">防火负责人：</td>
              <td class="aux_intable_td2">${requisitionVO.fireproofingMan }</td>
			  </tr>
            <tr>
              <td class="aux_intable_td1">许可证号：</td>
              <td class="aux_intable_td2">${requisitionVO.requisitionNumber }</td>
              <td class="aux_intable_td1">装修施工期限：</td>
              <td class="aux_intable_require_more"><table border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td>&nbsp;从&nbsp;</td>
                    <td><input name="beginDate" id="beginDate" type="text" class="inputtext required validate-date"
                    			value="<fmt:formatDate pattern='yyyy-MM-dd' value='${licenceVO.beginDate}'/>"  onchange="setDays();" size="8" /></td>
                    <td width="4">&nbsp;</td>
                    <td width="4"><img id="imgBeginDate" src="${ctx}/images/ico_clock_month.gif" width="20" height="20" /></td>
                    <td >&nbsp;至&nbsp;</td>
                    <td><input name="endDate" id="endDate" type="text" class="inputtext required validate-date great-equals-than-beginDate"
                    			value="<fmt:formatDate pattern='yyyy-MM-dd' value='${licenceVO.endDate}'/>"  onchange="setDays();" size="8" /></td>
                    <td width="4">&nbsp;</td>
                    <td><img id="imgEndDate" src="${ctx}/images/ico_clock_month.gif" width="20" height="20" /></td>
                    <td>共</td>
                    <td><input name="renovateDays" id="renovateDays" type="text" class="inputtext" value="40" style="text-align:right" size="1" readonly="readonly" /></td>
                    <td>天</td>
                  </tr>
              </table></td>
            </tr>
            <tr>
              <td class="aux_intable_td1">发证状态：</td>
              <td class="aux_intable_require_more">

              <pms:unitedSelect
               		id="state"
               		name="state"
               		optionLabel="name"
               		optionValue="value"
               		selectText="请选择..."
               		dataList="${licenceStates}"
               		className="select-one-required"
               		value="${licenceVO.state}"
               		style="width:110px;">
	         	</pms:unitedSelect>

<!--
              <c:if test="${requisitionVO.processState != '001'}">
              	<input id="state" name="state" value="${licenceVO.state}" type="hidden">
				<span>${licenceVO.renovateLicenceStateView }</span>
              </c:if>
 -->
              </td>
              <td class="aux_intable_td1">经办时间：</td>
              <td class="aux_intable_td2">${sysCurrentDate}</td>
            </tr>
            <tr>
              <td class="aux_intable_td1">装修单位：</td>
              <td class="aux_intable_td2">${requisitionVO.companyName}</td>
              <td class="aux_intable_td1">经办人：</td>
              <td class="aux_intable_td2">${transactor}</td>
            </tr>
            <tr>
              <td valign="top" class="aux_intable_td1">装修项目：</td>
              <td valign="top" class="aux_intable_td2" >${requisitionVO.items}</td>
              <td valign="top" class="aux_intable_td1">备 注：</td>
              <td class="aux_intable_require_more" valign="top"><textarea name="remark" id="remark" cols="28" rows="3" class="required  max-length-200" >${licenceVO.remark}</textarea></td>
            </tr>
        </table></td>
      </tr>
    </table>
</form>

    </td>
  </tr>




</table>
</div>


<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td class="window_footer"><table border="0" cellspacing="0" cellpadding="0">
      <tr>
	   <td><table border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td class="buttonOffLeft" id="btn1_41"></td>
            <td class="buttonOffMiddle" id="btn1_42" onMouseOver="btn_change_over(4)" onMouseOut="btn_change_out(4)" onblur="btn_change(4)" onclick="submitAndPreview();"><a href="#"  onclick=""onfocus="this.blur()"><img src="${ctx}/images/ico_Confirmation.gif" alt="" width="14" height="14" border="0" align="absbottom" /> 保存并预览</a></td>
            <td class="buttonOffRight" id="btn1_43"></td>
          </tr>
        </table></td>
        <td class="btn_between_space"></td>

        <td><table border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td class="buttonOffLeft" id="btn1_21"></td>
              <td class="buttonOffMiddle" id="btn1_22" onClick="submitWin();" onMouseOver="btn_change_over(2)" onMouseOut="btn_change_out(2)" onBlur="btn_change(2)"><img src="${ctx}/images/ico_ok.gif" alt="" width="14" height="14" border="0" align="absbottom" /> 保 存</td>
              <td class="buttonOffRight" id="btn1_23"></td>
            </tr>
        </table></td>
        <td class="btn_between_space"></td>
        <td><table border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td class="buttonOffLeft" id="btn1_31"></td>
              <td class="buttonOffMiddle" id="btn1_32" onClick="windowClose();" onMouseOver="btn_change_over(3)" onMouseOut="btn_change_out(3)" onBlur="btn_change(3)"><img src="${ctx}/images/ico_cancel.gif" alt="" width="14" height="14" border="0" align="absbottom" /> 关 闭</td>
              <td class="buttonOffRight" id="btn1_33"></td>
            </tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
</table>


<script type="text/javascript">

              Calendar.setup(
              {
	              inputField : "beginDate", // ID of the input field
	              ifFormat : "%Y-%m-%d", // the date format
	              button : "imgBeginDate", // ID of the button
	             // align          :    "Tl",           // alignment (defaults to "Bl")
			      singleClick    :    true
              }
              );

              Calendar.setup(
              {
	              inputField : "endDate", // ID of the input field
	              ifFormat : "%Y-%m-%d", // the date format
	              button : "imgEndDate", // ID of the button
	             // align          :    "Tl",           // alignment (defaults to "Bl")
			      singleClick    :    true
              }
              );

</script>

</body>
</html>